import React, { Component } from 'react'
import Spread from './Spread'
import ThemeContext from './context/theme-context'
import User from './User'
import UserContext from './context/user-context'
import Banner from './Banner'

class App extends Component {
  constructor() {
    super()
    this.state = {
      user: {
        name: '张三',
        age: 13
      }
    }
  }
  render() {
    const { user } = this.state
    return (
      <div>
        {/* spread语法：方式一 */}
        <Spread name={user.name} age={user.age} />
        {/* spread语法：方式二 */}
        <Spread {...user} />
        {/* Context语法 */}
        {/* <ThemeContext.Provider value={user}>
          <User />
        </ThemeContext.Provider> */}
        {/* 嵌套多个Context */}
        <UserContext.Provider value={{ name: '李四', age: 22, avatar: 'xxx' }}>
          <ThemeContext.Provider value={user}>
            <User />
          </ThemeContext.Provider>
        </UserContext.Provider>
        {/* Context组件外的可以使用context设置的默认值 */}
        <Banner />
      </div>
    )
  }
}

export default App